﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;

using xfsale.lib;
using xfsale.packet;

namespace xfsale.ui
{
    public partial class WinIdentify : Form
    {
        public WinIdentify()
        {
            InitializeComponent();
        }

        private void WinIdentify_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.Retry)
            {
                e.Cancel = true;
            }
        }

        private void WinIdentify_Load(object sender, EventArgs e)
        {
            SysControl.InitCtrl(CmbIdentifyType, "IdentifyType");
        }

        private void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                //填充请求数据
                CustomerRequest request = new CustomerRequest();
                request.identifyType = SysControl.GetCtrlValue(CmbIdentifyType);
                request.identifyCode = SysControl.GetCtrlValue(TxtIdentifyCode);

                //调用服务
                CustomerResponse response = (CustomerResponse)App.CallInfoService("getCustomer", request);

                //处理应答结果
                if (response.returnCode == "0000")
                {
                    //MessageBox.Show(response.returnMsg);
                    App.Customer.Identified = true;
                    App.Customer.TransAccountID = response.transAccountID;
                    App.Customer.CustAccountID = response.custAccountID;
                    App.Customer.CustName = response.custName;
                    App.Customer.CustNameAbbr = response.custNameAbbr;
                    App.Customer.CustType = response.custType;
                    App.Customer.Nationality = response.nationality;
                    App.Customer.CertType = response.certType;
                    App.Customer.CertNo = response.certNo;
                    DialogResult = DialogResult.OK;
                    return;
                }
                else
                {
                    SysMessage.Error(response.returnMsg);
                    DialogResult = DialogResult.Retry;
                    return;
                }
            }
            catch (Exception ex)
            {
                SysMessage.Error(ex.Message);
            }
        }

        private void CmbIdentifyType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
